package com.zero.jewelry.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zero.common.core.domain.page.PageDomain;
import com.zero.jewelry.vo.ReviewVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zero.common.annotation.log.Log;
import com.zero.common.core.basecontroller.BaseController;
import com.zero.common.core.domain.result.AjaxResult;
import com.zero.common.core.enums.BusinessType;
import com.zero.jewelry.domain.Review;
import com.zero.jewelry.service.IReviewService;
import com.zero.common.core.utils.poi.ExcelUtil;
import com.zero.common.core.domain.page.TableDataInfo;

/**
 * 评论管理Controller
 * 
 * @author cai-xu-kun
 * @date 2025-09-15
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "评论管理")
@RequestMapping("/jewelry/review")
public class ReviewController extends BaseController {

    private final IReviewService reviewService;

    /**
     * 查询评论管理分页
     */
    @ApiOperation("查询评论管理分页")
    @PreAuthorize("@ss.hasPermi('jewelry:review:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReviewVo vo) {
        PageDomain pageDomain = this.startPage();
        Page<ReviewVo> p = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<ReviewVo> page = reviewService.selectReviewVoListPage(vo, p);
        return this.getDataTable(page);
    }

    /**
     * 导出评论管理列表
     */
    @ApiOperation("导出评论管理列表")
    @PreAuthorize("@ss.hasPermi('jewelry:review:export')")
    @Log(title = "评论管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReviewVo vo) {
        List<ReviewVo> list = reviewService.selectReviewVoList(vo);
        ExcelUtil<ReviewVo> util = new ExcelUtil<ReviewVo>(ReviewVo.class);
        util.exportExcel(response, list, "评论管理数据");
    }

    /**
     * 获取评论管理详细信息
     */
    @ApiOperation("获取评论管理详细信息")
    @PreAuthorize("@ss.hasPermi('jewelry:review:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(reviewService.selectReviewById(id));
    }

    /**
     * 新增评论管理
     */
    @ApiOperation("新增评论管理")
    @PreAuthorize("@ss.hasPermi('jewelry:review:add')")
    @Log(title = "评论管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Review review) {
        return toAjax(reviewService.insertReview(review));
    }

    /**
     * 修改评论管理
     */
    @ApiOperation("修改评论管理")
    @PreAuthorize("@ss.hasPermi('jewelry:review:edit')")
    @Log(title = "评论管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Review review) {
        return toAjax(reviewService.updateReview(review));
    }

    /**
     * 删除评论管理
     */
    @ApiOperation("删除评论管理")
    @PreAuthorize("@ss.hasPermi('jewelry:review:remove')")
    @Log(title = "评论管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(reviewService.deleteReviewByIds(ids));
    }
}
